package org.celery.modules.goods.wrapper;

import lombok.AllArgsConstructor;
import org.celery.modules.goods.entity.Goods;
import org.celery.modules.goods.service.IGoodsService;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.celery.modules.goods.entity.GoodsStyle;
import org.celery.modules.goods.vo.GoodsStyleVO;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;

/**
 * 商品款式表包装类,返回视图层所需的字段
 *
 * @author Celery
 * @since 2022-03-30
 */
public class GoodsStyleWrapper extends BaseEntityWrapper<GoodsStyle, GoodsStyleVO>  {

    public static GoodsStyleWrapper build() {
        return new GoodsStyleWrapper();
    }

	@Override
	public GoodsStyleVO entityVO(GoodsStyle goodsStyle) {
		GoodsStyleVO goodsStyleVO = BeanUtil.copy(goodsStyle, GoodsStyleVO.class);
		IGoodsService goodsService = SpringUtil.getBean(IGoodsService.class);

		Goods goods = goodsService.getById(goodsStyle.getGoodsId());
		if (Func.isNotEmpty(goods)) {
			goodsStyleVO.setGoodsName(goods.getName());
		}

		return goodsStyleVO;
	}

}
